package com.example.ioc_demo;

import org.springframework.stereotype.Controller;

public class CarExample {
    public static void main(String[] args) {
        Tire tire = new Tire(17);
        Bottom bottom = new Bottom(tire);
        CarBody carBody = new CarBody(bottom);
        Car car = new Car(carBody);
        car.run();
    }

    static class Car {
        //在创建汽车之前，需要先创建车车身
        private CarBody carBody;

        public Car(CarBody carBody) {
            this.carBody = carBody;
            //车身初始化完成
            System.out.println("Car init....");
        }
        public void run() {
            System.out.println("car start");
        }

    }
    static class CarBody {
        //在创建车身之前，需要依赖地盘
        private Bottom bottom;
        public CarBody(Bottom bottom) {
            this.bottom = bottom;
            System.out.println("CarBody init....");
        }
    }

    static class Bottom {
        //在创建地盘之前，需要先创建出轮子
        private Tire tire;
        public Bottom(Tire tire) {
            this.tire = tire;
            System.out.println("Bottom init....");
        }
    }

    static class Tire {
        //定义车轮的尺寸
        private int size;
        public Tire(int size) {
            this.size = size;
            System.out.println("tire init...");
        }
    }
}
